﻿var role_grid = mini.get("role_grid");
var tree_grid = mini.get("treegrid1");
function customSelectionChanged(e) {
    var _grid = e.sender;
    var record = _grid.getSelected();
    if (record) {
        var condition = "condition=" + "user_id='" + record.id + "'";
        role_grid.setUrl("/extendpage/data/jsondata.aspx?entity=v_t_sys_user_role&" + condition);
        role_grid.load({});
        tree_grid.setUrl("/extendpage/data/jsondata.aspx?entity=v_user_menu&type=1&" + condition)
        tree_grid.load({});
    }
}



//移除角色
var fnRemoveRole = function () {
    var rows = role_grid.getSelecteds();
    var record = grid.getSelected();
    if (rows.length > 0) {
        if (confirm("确定删除选中记录？")) {
            var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                ids.push(r.role_id);
            }
            var id = ids[0]; //ids.join(',');
            role_grid.loading("操作中，请稍后......");
            $.ajax({
                url: "/extendpage/data/jsondata.aspx?type=1&entity=t_sys_user_role&condition=user_id='" + record.id + "' and role_id='" + id + "'",
                success: function (text) {
                    //依赖于jquery.json.2.2.js
                    var c = $.evalJSON(text);
                    $.ajax({
                        url: "/extendpage/action/datasave.aspx?entity=t_sys_user_role&action=delete&id=" + c[0].id + "&r=" + Math.random(),
                        success: function (text) {
                            if (text == 1) {
                                alert("删除成功!");
                            }
                            role_grid.reload();
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert(jqXHR.responseText);
                            role_grid.reload();
                        }
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    role_grid.reload();
                }
            });

        }
    } else {
        alert("请选中一条记录");
    }
}